package android.slc.db_objectbox.sys.service.imp;

import android.slc.db_objectbox.core.ObjectBox;
import android.slc.db_objectbox.sys.entity.CsDictType;
import android.slc.db_objectbox.sys.entity.CsDictType_;
import android.slc.db_objectbox.sys.service.CsDictTypeDaoService;

import androidx.annotation.NonNull;

import io.objectbox.Box;
import io.objectbox.query.QueryBuilder;

/**
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2021/8/13 14:29
 */
public class CsDictTypeDaoServiceImp extends android.slc.db_objectbox.sys.service.imp.DaoServiceImp<CsDictType> implements CsDictTypeDaoService {
    @Override
    protected String getEntityName() {
        return "dictType";
    }

    @Override
    public Box<CsDictType> getBox() {
        return ObjectBox.getBox(CsDictType.class);
    }

    @Override
    protected void checkEntity(CsDictType entity) {
        super.checkEntity(entity);
        CsDictType csDictType = findDictTypeByDictType(entity.getDictType());
        if (csDictType != null && csDictType.getDictId() != null) {
            entity.setDictId(csDictType.getDictId());
        }
    }

    @Override
    public CsDictType findDictTypeByDictType(@NonNull String dictType) {
        return getBox().query().equal(CsDictType_.dictType, dictType, QueryBuilder.StringOrder.CASE_SENSITIVE).build().findUnique();
    }
}
